package com.foreknow.oopTest;

import java.util.Scanner;

/**
 * @author shkstart
 * @create 2021-07-23 14:36
 */
public class bookTest {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double money=0;
        Book[] books=new Book[3];
        order[] orders=new order[books.length];
        for (int i = 0; i < orders.length; i++) {
            orders[i]=new order();
        }
        Book book1 = new Book(1, "java", 33.45, 50);
        Book book2 = new Book(2, "jsp", 55.45, 150);
        Book book3 = new Book(3, "ssm", 77.45, 250);
        books[0]=book1;
        books[1]=book2;
        books[2]=book3;


        book1.showAll();
        book2.showAll();
        book3.showAll();


        for (int i = 0; i <=2 ; i++) {
            System.out.println("请输入图书编号");
            int id = sc.nextInt();

            System.out.println("请输入购买数量");
            int num = sc.nextInt();
            System.out.println("请继续购买图书");
            for (int j = 0; j <books.length ; j++) {
                if(id==books[j].getBid()){
                   books[j].setNum(books[j].getNum()-num);
                   money+=books[j].getPrice()*num;
                    orders[i].setOrbook(books[j].getBookname());
                    orders[i].setPrice(books[j].getPrice());
                    orders[i].setOrnum(num);

                }
            }
        }

        System.out.println("订单的总额为"+money);
        for (int i = 0; i < orders.length; i++) {
            System.out.println(orders[i].getOrbook()+"---"+orders[i].getPrice()+"---"+orders[i].getOrnum());
        }




    }
}
